import java.util.Arrays;

public class demo {
    public static void main(String[] args) {
        /*int[] array = null;
        System.out.println(array[0]);//空指针异常*/

        //for-each
        /*int[] array = {1,2,3,4};
        for(int x :array){
            System.out.print(x+" ");
        }
        System.out.println();
        String ret = Arrays.toString(array);
        System.out.println(ret);*/



        //数组转字符串
        /*int[] a = null;
        String ret = myToString(a);
        System.out.println(ret);*/



        //数组拷贝(拷贝跟复制不一样!!,复制是引用了同一个数组,指向同一个对象)
        /*int[] array = {1,2,3,4};

        int[] copy = Arrays.copyOf(array,array.length*2);//可以扩容,指向了新的数组空间,扩大了二倍
        System.out.println(Arrays.toString(copy));*/



        /*int[] a = {1,456,23,43};
        Arrays.sort(a);//排序
        System.out.println(Arrays.toString(a));
        System.out.println(binarySearch(a,456));*/



    }

    //自设一个toString方法
    //把一个整型数组转换为字符串
    /*public static String myToString(int[] array ){
        assert array !=null;//需要设置idea才能用这行代码
        if(array==null){
            return "null";
        }
        String ret = "[";
        for (int i = 0; i < array.length; i++) {
            ret += array[i];
            if(i != array.length-1){
               ret+=",";
            }
        }
        ret+="]";
        return ret;
    }*/


    //二分查找
    /*public static int binarySearch(int[] array,int key){
        //key是要找的数据
        int i = 0;
        int j = array.length-1;
        while (i<=j){
            int mid = (i+j)/2;
            if(array[mid]<key){
                i = mid+1;
            } else if (array[mid]==key) {
                return mid;
            }else {
                j = mid-1;
            }
        }
        return -1;
    }*/

}
